package chain_of_responsibility_pattern.exercise.exercise1;

/**
 * 广告过滤器
 * @author ricejson
 */
public class AdvertisementFilter extends Filter {
    private static final String SENSITIVE_WORD = "促销";

    @Override
    public String filter(String text) {
        // 将敏感词替换为**
        String newText = text.replaceAll(SENSITIVE_WORD, "**");
        // 交给下一级过滤器
        if (successor != null) {
            return successor.filter(newText);
        } else {
            return newText;
        }
    }
}
